<?php
defined('PHPFOX') or exit('NO DICE!');

class Hoidap_Service_Hoidap extends Phpfox_Service 
{
	public function __construct()
	{
		$this->_sTable = Phpfox::getT('hoidap_cauhoi');
	}	
	
	public function getHoiDap($idcauhoi)
	{
//	return "getcauhoi";
	
		// (($sPlugin = Phpfox_Plugin::get('blog.component_service_blog_getblog__start')) ? eval($sPlugin) : false);
		// (($sPlugin = Phpfox_Plugin::get('blog.service_blog_getblog')) ? eval($sPlugin) : false);
		
		// if (Phpfox::isModule('track'))
		// {
			// $this->database()->select("blog_track.item_id AS is_viewed, ")->leftJoin(Phpfox::getT('blog_track'), 'blog_track', 'blog_track.item_id = blog.blog_id AND blog_track.user_id = ' . Phpfox::getUserBy('user_id'));
		// }		
				
		// if (Phpfox::isModule('friend'))
		// {
			// $this->database()->select('f.friend_id AS is_friend, ')->leftJoin(Phpfox::getT('friend'), 'f', "f.user_id = blog.user_id AND f.friend_user_id = " . Phpfox::getUserId());					
		// }		
		
		if (Phpfox::isModule('like'))
		{
			$this->database()->select('l.like_id AS is_liked, ')->leftJoin(Phpfox::getT('like'), 'l', 'l.type_id = \'hoidap\' AND l.item_id = hd.cauhoi_id AND l.user_id = ' . Phpfox::getUserId());
		}
		
		// $aRow = $this->database()->select("blog.*, " . (Phpfox::getParam('core.allow_html') ? "blog_text.text_parsed" : "blog_text.text") ." AS text, " . Phpfox::getUserField())
			// ->from($this->_sTable, 'blog')
			// ->join(Phpfox::getT('blog_text'), 'blog_text', 'blog_text.blog_id = blog.blog_id')
			// ->join(Phpfox::getT('user'), 'u', 'u.user_id = blog.user_id')
			// ->where('blog.blog_id = ' . (int) $iBlogId)
			// ->execute('getSlaveRow');		

			
			
		mysql_query("set names'utf8'");
		$aRow = $this->database()->select("hd.*, hd_c.category_name, hd_c.category_parent, ". Phpfox::getUserField())
			->from($this->_sTable, 'hd')
			->join(Phpfox::getT('user'), 'u', 'u.user_id = hd.user_id')
			->join(Phpfox::getT('hoidap_category'), 'hd_c', 'hd_c.category_id = hd.category_id')
			->where('hd.post_status=1 AND hd.cauhoi_id = ' . (int) $idcauhoi)
			->execute('getSlaveRow');	
		// (($sPlugin = Phpfox_Plugin::get('blog.component_service_blog_getblog__end')) ? eval($sPlugin) : false);
		
	/* 	if (!isset($aRow['is_friend']))
		{
			$aRow['is_friend'] = 0;
		}
		 */
		return $aRow;
		
	}	
	
	public function updateStatus($idcauhoi)
	{
		$oFilter = Phpfox::getLib('parse.input');				
		$idcauhoi = $oFilter->clean($idcauhoi, 255);

		$this->database()->updateCounter('hoidap_cauhoi', 'total_view', 'cauhoi_id', $idcauhoi);	
	}	
}

?>